package com.example.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.sys.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select " +
            "a.id, " +
            "a.username, " +
            "a.password, " +
            "a.phone, " +
            "a.open_id, " +
            "a.create_time, " +
            "a.nickname, " +
            "a.avatar, " +
            "b.id as role, " +
            "b.name as role_name " +
            "from sys_user a, sys_role b " +
            "where a.role = b.id and (a.username = #{username} or a.phone = #{username})")
    User loginByUsernameOrPhone(String username);

    @Select("select " +
            "a.id, " +
            "a.username, " +
            "a.password, " +
            "a.phone, " +
            "a.open_id, " +
            "a.create_time, " +
            "a.nickname, " +
            "a.avatar, " +
            "b.id as role, " +
            "b.name as role_name " +
            "from sys_user a, sys_role b " +
            "where a.role = b.id and a.open_id = #{openid} ")
    User getOneByOpenId(String openid);
}
